package com.pidan.start;

import com.pidan.pojo.Product;
import com.pidan.util.IOutil;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class SystemStart {

    public static void main(String[] args) throws AWTException {
        try {
            Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
            Transferable tText = null;
            List<Product> input = IOutil.input("F:/tbk/data/2021-03-28.data");
            String[] lists = {"我只爱你四天,春天夏天秋天冬天", "我只爱你三天,昨天,今天,明天.", "我只爱你两天,白天,黑天", "我只爱你一天,每一天", "爱你么么哒"};
            Robot robot = new Robot();
            robot.delay(5000);//延迟十秒，主要是为了预留出打开窗口的时间，括号内的单位为毫秒
            for (int i = 0; i < input.size(); i++) {//循环五次，当然，如果爱得深，你死循环也没问题设置为100
//                Product product = input.get(i);
//                System.out.println(product.getImgURL());
//                clip.setContents(getImageTrans(product.getImgURL()), null);
                robot.keyPress(KeyEvent.VK_CONTROL);
//                robot.keyPress(KeyEvent.VK_V);
//                TimeUnit.SECONDS.sleep(1);
  //              tText = new StringSelection("\n" + product.toString()); //自己定义就需要把这行注释，下行取消注释
                tText = new StringSelection("@日\uD83D\uDC37 侠   醒醒别睡-----" );
                clip.setContents(tText, null);
                robot.keyPress(KeyEvent.VK_V);
                TimeUnit.MILLISECONDS.sleep(100);
                robot.keyPress(KeyEvent.VK_ENTER);
                robot.keyRelease(KeyEvent.VK_CONTROL);
                robot.delay(300);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static Transferable getImageTrans(String url) throws IOException {

        File file = new File(url);
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        BufferedImage bi = ImageIO.read(bis);
        Image image = (Image) bi;
        Transferable trans = new Transferable() {
            public DataFlavor[] getTransferDataFlavors() {
                return new DataFlavor[]{DataFlavor.imageFlavor};
            }

            public boolean isDataFlavorSupported(DataFlavor flavor) {
                return DataFlavor.imageFlavor.equals(flavor);
            }

            public Object getTransferData(DataFlavor flavor)
                    throws UnsupportedFlavorException, IOException {
                if (isDataFlavorSupported(flavor))
                    return image;
                throw new UnsupportedFlavorException(flavor);
            }

        };
        return trans;
    }
}
